package implementation.menu {
import flash.display.DisplayObjectContainer;
import flash.display.Sprite;
import flash.geom.Rectangle;

import palf.menu.MenuAbstractFactory;
import palf.menuItems.MenuItem;
import palf.visualEffects.VisualEffectBuilder;

/* Defines the implementation for creating the Menu */
/* replace this factory to define different MenuItems and default styles for existing MenuItems */

internal class MenuAbstractFactoryImplementation implements MenuAbstractFactory {

	private const VISUAL_EFFECTS : VisualEffectBuilder = new VisualEffectBuilder();

	private var bounds : Rectangle;
	private var canvas : DisplayObjectContainer;
	private var active : DisplayObjectContainer;
	private var holder : DisplayObjectContainer;

	public function MenuAbstractFactoryImplementation(canvas : DisplayObjectContainer) {
		this.canvas = canvas;
		this.active = createEmptySprite();
		this.holder = createEmptySprite();
		this.bounds = new Rectangle(0, 10, canvas.width, canvas.height);
	}

	private function createEmptySprite() : Sprite {
		var sprite : Sprite = new Sprite();
		canvas.addChild(sprite);
		return sprite;
	}

	public function draw(item : MenuItem) : void {
		item.draw(active);
	}

	public function clear() : void {
		while (active.numChildren > 0) {
			holder.addChild(active.getChildAt(0));
		}
		VISUAL_EFFECTS.slideRight(holder, bounds)
	}

	public function sort() : void {
		VISUAL_EFFECTS.column(active, bounds);
		VISUAL_EFFECTS.fadeIn(active);
	}
}
}
